package com.wwy.config;

/**
 * @author 王伟羽
 * @date 2024/3/13 9:39
 */

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 配置获取RabbitMq的静态方法
 */

public class RabbitMqUtils {


    public static   Connection getConnection() {
        ConnectionFactory factory = new ConnectionFactory();   //创建连接工厂
        //设置相关属性
        factory.setUsername("guest");
        factory.setPassword("guest");
        factory.setVirtualHost("/");
        factory.setHost("192.168.60.139");
        factory.setPort(5672);
        try {
            //获取连接
            Connection conn = factory.newConnection();
            return conn;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        } catch (TimeoutException e) {
            e.printStackTrace();
            return null;
        }

    }
}
